<template>
  <div>
    <el-form :inline="true" class="demo-form-inline" style="text-align: left">
      <el-form-item>
        <el-form-item label="巡更路线名称">
          <el-input placeholder="巡更路线名称"></el-input>
        </el-form-item>
        <el-button
          style="background-color: green; color: white"
          icon="el-icon-search"
          @click="list"
          >查询</el-button
        >
        <el-button style="color: gray" icon="el-icon-refresh">重置</el-button>
        <el-button style="color: green" icon="el-icon-plus" @click="add"
          >新增</el-button
        >
      </el-form-item>
    </el-form>
    <template>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="id" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="userId" label="巡更人员姓名" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.userId == 1">张三</span>
            <span v-if="scope.row.userId == 2">李四</span>
            <span v-if="scope.row.userId == 3">王五</span>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="电话" align="center">
        </el-table-column>
        <el-table-column prop="remark" label="备注" align="center">
        </el-table-column>
        <el-table-column label="操作" align="center">
          <el-button type="text" style="color: red" @click="del"
            >删除</el-button
          >
        </el-table-column>
      </el-table>
    </template>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="formInline.pageIndex"
      :page-sizes="[1, 2, 3, 4]"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="countnum"
    >
    </el-pagination>
  </div>
</template>
<script>
import {
  GetShowPatrolPerson,
  deletePatrolPerson,
  GetTotaocount,
} from "@/api/SafeManage/PatrolPerson";
export default {
  data() {
    return {
      tableData: [],
      dialogFormVisible: false,
      multipleSelection: [],
      ids: {},
      formInline: {
        pageIndex: 1,
        pageSize: 2,
      },
      countnum: 0,
      count: 0,
    };
  },
  created() {
    this.list();
    this.totalcount();
  },
  methods: {
    //显示
    list() {
      GetShowPatrolPerson(this.formInline).then((res) => {
        this.tableData = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    handleSizeChange(val) {
      this.formInline.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.formInline.pageIndex = val;
      this.list();
    },
    totalcount() {
      GetTotaocount().then((res) => {
        this.countnum = res.data;
      });
    },
    //全选/反选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //删除
    del() {
      if (this.multipleSelection.length <= 0) {
        this.$message.error("请选择一条数据");
        return;
      }

      this.multipleSelection.forEach((res) => {
        this.ids.id = res.id;
      });
      deletePatrolPerson(this.ids).then((res) => {
        if (res.data) {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.list();
        } else {
          this.$message.error("删除失败");
          return;
        }
      });
    },
    //跳转
    add() {
      this.$router.push("/SafeManage/AddPatrolPerson");
    },
  },
};
</script>
<style>
</style>